package com.jw.blog.config;

import com.jw.blog.interceptor.AccessInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;


/**
 * @author wan Email-wlf18726994755@163.com
 * @version 1.0
 * @className MyWebConfigurer
 * @date 2020/6/26 10:10
 **/
@Configuration
public class MyWebConfigurer implements WebMvcConfigurer {

    @Resource
    private AccessInterceptor accessInterceptor;
    /**
     * 静态资源映射，此处映射的是绝对路径，与项目路径分离。
     * @param registry w
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String s = System.getProperty("user.dir");

        registry.addResourceHandler("/upload/**").addResourceLocations(
               "file:"+ s+"/upload/");
    }

    /**
     * 拦截器
     * @param registry 我
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //添加拦截器
        registry.addInterceptor(accessInterceptor);
    }
}
